package insert

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"

	"github.com/tealeg/xlsx"
)

func ReadExcel(path string) {
	xlFile, err := xlsx.OpenFile(path)
	if err != nil {

	}
	count := 0
	sheet := xlFile.Sheets[7]
	i := 0
	for i = 0; i < 5; i++ {
		for _, row := range sheet.Rows {
			if len(row.Cells) > i {
				cell := row.Cells[i]
				str, _ := cell.String()
				if str != "" {
					count++
					fmt.Printf("\"%s\",", str)
				}
			}
		}
	}
}

// ReadJson 读取文件的 json 数据
func ReadJson(filepath string) interface{} {
	var f interface{}
	bytes, err := ioutil.ReadFile(filepath)
	if err != nil {
		log.Println("read file error: ", err)
		os.Exit(1)
	}
	log.Println("reading file " + filepath)
	if err := json.Unmarshal(bytes, &f); err != nil {
		log.Println("parse json error: ", err)
	}
	log.Println("parse json successful: ", f)
	return f
}
